package com.example.demo.demos.web.test;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/return")
@Controller
public class ret {

    @RequestMapping("/m1")
    public String m1(){
        return "/index1.html";
    }

    @ResponseBody
    @RequestMapping("/m2")
    public String m2(){
        return "数据";
    }

    @ResponseBody
    @RequestMapping("/m3")
    public String m3(){
        return "<h1>test</h1>";
    }

    @RequestMapping("/m4")
    @ResponseBody
    public Person m4(){
        Person person = new Person();
        person.setName("zyh");
        person.setAge(20);
        return person;
    }

    @RequestMapping("/m5")
    @ResponseBody
    public Map<String,String> m5(){
        HashMap<String, String> map = new HashMap<>();
        map.put("k1","v1");
        map.put("k2","v2");
        map.put("k3","v3");
        return map;
    }

    @RequestMapping(value = "/m6",produces = "application/json;charset=utf8")
    @ResponseBody
    public String m6(HttpServletResponse response){
        response.setStatus(401);
        return "{'ok':1}";
    }
}
